{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "45cbe028",
   "metadata": {},
   "source": [
    "____\n",
    "* 2023-10-18\n",
    "* 课程：python语言\n",
    "* week05\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b07b8fe6",
   "metadata": {},
   "source": [
    "# 1.用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ed47bb63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：melyon\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'melyon'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input(\"请输入你的账号：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3ddd0d32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：melyon\n",
      "请输入你的密码：123456\n"
     ]
    }
   ],
   "source": [
    "username = input(\"请输入你的账号：\")\n",
    "password = input(\"请输入你的密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6e5103cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "melyon\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2a6cc7ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：melyon\n",
      "请输入你的密码：111111\n",
      "你输入的账户或者密码错误\n"
     ]
    }
   ],
   "source": [
    "# 假设 正确的账号：melyon\n",
    "# 假设 正确的密码：123456\n",
    "\n",
    "# 登陆系统\n",
    "username = input(\"请输入你的账号：\")\n",
    "password = input(\"请输入你的密码：\")\n",
    "# 两种登陆可能，1：登陆成功，2：登陆失败\n",
    "if username == \"melyon\" and password == \"123456\":\n",
    "    # 情景1： 账户和密码都正确，则登陆成功\n",
    "    print(\"欢迎VVVIP账户回来~~~\")\n",
    "else:\n",
    "    # 情景2：账户或者密码存在不正确的数据\n",
    "    print(\"你输入的账户或者密码错误\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7aab0e79",
   "metadata": {},
   "source": [
    "* 笔记：\n",
    "> 1. == 代表判断左右两边是否相等，即“等于”\n",
    "> 2. 所有的符号要用英文的符号，例如冒号:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c792677",
   "metadata": {},
   "source": [
    "# 2. 用户输出（格式化）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8cdc3255",
   "metadata": {},
   "source": [
    "## 2.1 注释\n",
    "> 1. 注释的内容（code）是不会被执行的\n",
    "> 2. \\# 注释内容\n",
    "> 3. \"\"\" 注释内容 \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "33f8dc0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第一种：# 表示单行注释，如上述用户输入的学习中，每一行进行文字描述的注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "eedb9a5f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "111\n"
     ]
    }
   ],
   "source": [
    "# 第二种：\"\"\"  注释内容 \"\"\" 多行注释，用于记录之前写过的程序，不会被执行\n",
    "\"\"\"\n",
    "import random\n",
    "wait_time = randow.randint(1,60)\n",
    "print(wait_time)\n",
    "\n",
    "word = \"bottles\"\n",
    "print(word)\n",
    "\"\"\"\n",
    "print(\"111\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae21c5d1",
   "metadata": {},
   "source": [
    "# 2.2 格式化输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "81cc4005",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的姓名:melyon\n",
      "请输入你的年龄:18\n",
      "请输入你的工作:Web3.0\n",
      "请输入你的薪水:50k\n"
     ]
    }
   ],
   "source": [
    "# 指定格式的简历\n",
    "\n",
    "#用户输入信息\n",
    "name = input(\"请输入你的姓名:\")\n",
    "age = input(\"请输入你的年龄:\")\n",
    "job = input(\"请输入你的工作:\")\n",
    "salary = input(\"请输入你的薪水:\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "96943717",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------- INFO melyon --------\n",
      "姓名: melyon\n",
      "年龄: 18\n",
      "工作: Web3.0\n",
      "薪水: 50k\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO = \"\"\"-------- INFO \"\"\" + name + \"\"\" --------\n",
    "姓名: \"\"\" + name + \"\"\"\n",
    "年龄: \"\"\" + age + \"\"\"\n",
    "工作: \"\"\" + job + \"\"\"\n",
    "薪水: \"\"\" + salary\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a067b65d",
   "metadata": {},
   "source": [
    "## 2.2.2 占位符实现格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ced5b907",
   "metadata": {},
   "source": [
    "* 笔记：上述代码使用的方法是“字符串的拼接”，用+实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1813693b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " -------- INFO melyon--------\n",
      "姓名: melyon\n",
      "年龄: 18\n",
      "工作: Web3.0\n",
      "薪水: 50k\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO = \"\"\" -------- INFO %s--------\n",
    "姓名: %s\n",
    "年龄: %s\n",
    "工作: %s\n",
    "薪水: %s\"\"\"%(name,name,age,job,salary)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "649f7fc6",
   "metadata": {},
   "source": [
    "* 笔记： 占位符比较适用于格式化字段较少的文本处理\n",
    "> 1. %s 占位符是字符串\n",
    "> 2. %d 占位符是数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "673aa9d3",
   "metadata": {},
   "source": [
    "## 2.2.3 格式化方法： format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1e792f16",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " -------- INFO melyon--------\n",
      "姓名: melyon\n",
      "年龄: 18\n",
      "工作: Web3.0\n",
      "薪水: 50k\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "# N:姓名，A:年龄，J：工作，S：薪水\n",
    "INFO = \"\"\" -------- INFO {N}--------\n",
    "姓名: {N}\n",
    "年龄: {A}\n",
    "工作: {J}\n",
    "薪水: {S}\"\"\".format(N = name, J = job, S = salary, A = age)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fe389d4",
   "metadata": {},
   "source": [
    "* 笔记：format方法可以解决占位符的两个痛点：\n",
    "> 1. 不再考量位置顺序\n",
    "> 2. 解决重复字段出现的问题，只需要赋值一次，如上述:N = name,只需要写一次即可"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa1de52a",
   "metadata": {},
   "source": [
    "# 3.课本第一章的三个项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a36c568",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 3.1 项目一： 判断时钟奇数分钟"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e22d62d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5fff3e9",
   "metadata": {},
   "source": [
    "## 3.2 项目二： 执行5次，每次等待随机秒钟，输出当时秒钟为奇数、偶数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a0940513",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"This minute seems a little odd.\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a4fd1a43",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "feea1515",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.4801290776555346\n",
      "0.5345927263416734\n",
      "0.869700985297239\n",
      "0.4056863201673159\n",
      "0.5260380557404293\n",
      "0.4099236943480389\n",
      "0.9512120486518514\n",
      "0.8562668472237979\n",
      "0.7157346303866945\n",
      "0.6207284072009862\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print(random.random())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11c18e43",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
